<template>
  <div class="basic-collapse-item-outer">
    <div class="basic-collapse-item-title-outer"  @click="click">
      <a-row justify="space-between" align="middle" :gutter="[0,8]">
        <a-col>
          <slot :title="title" name="title">{{ title }}</slot>
        </a-col>
        <a-col>
          <DownOutlined v-if="selected"/>
          <UpOutlined v-else/>
        </a-col>
      </a-row>
    </div>
    <div class="basic-collapse-item-main-outer" :class="classes">
      <div class="basic-collapse-item-main-body">
        <slot></slot>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import {defineComponent, ref, reactive, computed, onMounted} from 'vue'
import {DownOutlined, UpOutlined} from "@ant-design/icons-vue";

export default defineComponent({
  name: 'basic-collapse-item',
  components: {
    DownOutlined,
    UpOutlined
  },
  props: {
    selected: {
      type: [Boolean, String],
      default: 'false',
      validator(val) {
        if (val == null) return true;
        if (typeof val == "string") {
          return (['true', 'false'].indexOf(val) >= 0)
        } else return typeof val == 'boolean';
      }
    },
    title: {
      type: String,
      default: '',
      validator(val) {
        if (val == null) return true;
        return typeof val == "string"
      }
    }
  },
  setup(props: any, context) {
    const trans = (val: boolean | string) => {
      if (typeof val == 'string') return val == 'true'
      else return val;
    }


    // const selected = computed(() => trans(props.selected))
    const selected = ref(trans(props.selected))
    const title = computed(() => props.title)

    const click = ()=>{
      selected.value=!selected.value;
    }

    onMounted(()=>{
    })

    const classes=computed(()=>{
      let classesList=[];
      if(selected.value)classesList.push('basic-collapse-item-main-outer-show');
      else classesList.push('basic-collapse-item-main-outer-not-show')
      return classesList;
    })

    return {
      selected,
      title,
      click,
      classes
    }
  }
})
</script>
<style scoped>
.basic-collapse-item-outer {
  border-bottom: 1px #dfdfe1 solid;
  box-sizing: border-box;
  margin: 1px;
  padding: 1px 1px;
  overflow: hidden;
}

.basic-collapse-item-outer:last-child {
  border-bottom: 0;
}

.basic-collapse-item-title-outer {
  box-shadow: 0 0 0 0;
  box-sizing: border-box;
  border: 1px #ffffff solid;
  padding: 8px 8px;
  cursor: pointer;
  transition: all .32s cubic-bezier(.22, .61, .36, 1);
}

.basic-collapse-item-title-outer:focus {
  box-shadow: 0 0 0 1px #1364f1, 0 0 4px #1364f1;
}

.basic-collapse-item-title-outer:hover {
  box-shadow: 0 0 0 1px #1364f1, 0 0 4px #1364f1;
}

.basic-collapse-item-title-outer:active {
  box-shadow: 0 0 0 1px #1364f1, 0 0 4px #1364f1;
}

.basic-collapse-item-main-outer {
  margin-top: 4px;
  box-sizing: border-box;
  overflow: hidden;
  height: auto;
  transition: all .52s cubic-bezier(.22, .61, .36, 1);
}

.basic-collapse-item-main-outer-not-show {
  max-height: 1px;
}
.basic-collapse-item-main-outer-show {
  max-height: 300px;
  overflow: auto;
}

.basic-collapse-item-main-body {
  box-sizing: border-box;
  padding: 8px 8px;
  overflow: auto;
}

</style>
